home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #05 (Dec85-Jan86) / modula2 / serial ports 2-1 / SCCHack.MOD < prev   
Text File  |  1985-11-23  |  2KB  |  80 lines

  1.  
  2. MODULE SCCHack;
  3.  
  4. (*    Written by Jeff Mitchell
  5.         Digital Solutions,  1985
  6.         
  7. This program allows interactive manipulation
  8. of the internal SCC registers.    It uses only
  9. channel A but I've included the offsets for
  10. channel B for reference.                                        *)
  11.  
  12.  
  13. FROM    Terminal    IMPORT    Read,Write,WriteLn,
  14.                                                 WriteString,ClearScreen;
  15.                                                 
  16. FROM    InOut            IMPORT    ReadInt,WriteHex;                                                            
  17.  
  18.  
  19.     CONST
  20.         (* Offsets into SCC registers *)
  21.         aData        =  6;    (* A channel data *)
  22.         aCtl        =  2;    (* A channel control *)
  23.         bData        =  4;    (* B channel data *)
  24.         bCtl        =  0;    (* B channel control *)
  25.         cntl_B    =  2;    (* ASCII value *)
  26.         cntl_C    =  3;    (* ASCII value *)
  27.         NULL        =  0;    (* ASCII value *)
  28.         
  29.     TYPE
  30.         SerPtr    = POINTER TO ARRAY [0..6] OF CHAR;
  31.         (* Needed for byte access *)
  32.         
  33.     VAR
  34.         SCCRd [1D8H]: SerPtr;    (* Read pointer *)    
  35.         SCCWr    [1DCH]: SerPtr;    (* Write pointer *)
  36.         ch: CHAR;
  37.         reg: INTEGER;
  38.  
  39.  
  40. BEGIN    (* SCCHack *)
  41.     ClearScreen;
  42.     ch:= SCCRd^[aCtl];        (* Ensure ptr reg = 0 *)
  43.     
  44.     REPEAT
  45.         WriteString('Which register ? ');
  46.         ReadInt(reg);
  47.         WriteLn;
  48.         SCCWr^[aCtl]:= CHR(reg);        (* Set pointer *)
  49.         
  50.         REPEAT
  51.             WriteString('Read or Write? ');
  52.             Read(ch);
  53.             Write(ch);
  54.             WriteLn
  55.         UNTIL (CAP(ch) = 'R') OR (CAP(ch) = 'W');
  56.         
  57.         IF (CAP(ch) = 'R') THEN
  58.             ch:= SCCRd^[aCtl];                (* Read register *)
  59.             WriteHex(CARDINAL(ch),4);    (* Display in hex *)
  60.             WriteLn
  61.         ELSE    
  62.             WriteString('Register Value? ');
  63.             ReadInt(reg);            (* Integer value, not hex *)
  64.             WriteLn;
  65.             WriteString('Hex equivalent = ');
  66.             WriteHex(CARDINAL(reg),4);
  67.             WriteLn;
  68.             SCCWr^[aCtl]:= CHR(reg)    (* Write to register *)
  69.         END;
  70.         
  71.         REPEAT
  72.             WriteString('Try another? ');    (* Fun, huh? *)
  73.             Read(ch);
  74.             Write(ch);
  75.             WriteLn
  76.         UNTIL (CAP(ch) = 'Y') OR (CAP(ch) = 'N');
  77.         WriteLn
  78.     UNTIL (CAP(ch) <> 'Y')
  79.     
  80. END SCCHack.